package com.example.lin.common;

import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;

/**
 * @className: BaseExcel
 * @description: 导出工具类
 * @author: Lin.Gu
 * @date: 2024/2/6
 */
public class BaseExcel {
    /**
     * 导入文件类型转换
     *
     * @param xssfCell 表格信息
     * @return String
     */
    public static String getString(XSSFCell xssfCell) {
        if (xssfCell == null) {
            return "";
        }
        if (xssfCell.getCellTypeEnum() == CellType.NUMERIC) {
            if (xssfCell.getNumericCellValue() == (int)xssfCell.getNumericCellValue()) {
                return String.valueOf((int)xssfCell.getNumericCellValue());
            }
            return String.valueOf(xssfCell.getNumericCellValue());
        } else if (xssfCell.getCellTypeEnum() == CellType.BOOLEAN) {
            return String.valueOf(xssfCell.getBooleanCellValue());
        } else {
            return xssfCell.getStringCellValue();
        }
    }
}
